#include "udp_server.hpp"
#include"err.hpp"
#include<memory>

using namespace ns_server;
using namespace std;

//使用手册
//   ./udp_server port
static void usage(string proc)
{
    cout<<"Usage:\n\t"<<proc<<" port\n"<<std::endl;
}

//处理函数
std::string transation(std::string message)
{
    std::string responce;
    for(auto ch:message)
    {
        if(islower(ch))
            responce+=toupper(ch);
        else
            responce+=ch;
    }
    return responce;
}

int main(int argc,char*argv[])
{
    if(argc!=2)
    {
        usage(argv[0]);
        exit(USAGE_ERR);
    }
    //提取参数中的端口号
    uint16_t port=atoi(argv[1]);

    unique_ptr<UdpServer> usvr(new UdpServer(port,transation));
    usvr->InitServer();
    usvr->Start();

    return 0;
}